how we remove the special character from any string for example string sSpecailChar="rajesh have $280.00 Rs. only, What!?" in this sample how remove the special character like $!.? is the best solution of this problem
we use regex class which contain many important properties like relace(), split(), match() etc we remove the special char from any string for example: firstly, we use System.Text.RegularExpressions namespce string strData = "rajesh have $280.00 Rs. only, What!?"; string pattern = "[^a-zA-Z0-9]+"; Regex rgx = new Regex(pattern); Response.Write("<font color='green'>Before Replace: </font> " + strData+"<br/>"); Response.Write("<font color='green'>After Repalce: </font>" + rgx.Replace(strData, " ")); output: Untitled PageBefore Replace: rajesh have $280.00 Rs. only, What!? After Repalce: rajesh have 280 00 Rs only What
Liked By
Write Answer
Special character remove from url or any string
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy
Join MindStick Community
You have need login or register for voting of answers or question.
Amit Singh
06-Dec-2010we remove the special char from any string
for example:
firstly, we use System.Text.RegularExpressions namespce
string strData = "rajesh have $280.00 Rs. only, What!?";
string pattern = "[^a-zA-Z0-9]+";
Regex rgx = new Regex(pattern);
Response.Write("<font color='green'>Before Replace: </font> " + strData+"<br/>");
Response.Write("<font color='green'>After Repalce: </font>" + rgx.Replace(strData, " "));
output:
After Repalce: rajesh have 280 00 Rs only What